package com.epoint.action.clubInfo;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONObject;
import com.epoint.bizlogic.clubInfo.ClubInfoService;
import com.epoint.bizlogic.clubInfo.domain.ClubInfo;
import com.epoint.utils.RequestUtils;

/**
 * Servlet implementation class ClubEditAction
 */
@WebServlet("/clubeditaction")
public class ClubEditAction extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	ClubInfoService clubInfoService = new ClubInfoService();
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ClubEditAction() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	    String requestMethod = request.getParameter("method");
        String json = RequestUtils.reflectInvokMethod(requestMethod, request, ClubEditAction.class);
        response.getWriter().write(json);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}
	
	/**
         * 更新俱乐部信息
     * @param clubInfo 俱乐部信息
     * @return 结果
     */
    public String updateClubInfo(HttpServletRequest request) {
        String data = request.getParameter("data");
        ClubInfo clubInfo = JSONObject.parseObject(data, ClubInfo.class);
        System.out.println(clubInfo);
        int i = clubInfoService.updateClubInfo(clubInfo);
        if (i > 0) {
            return "修改成功";
        } else  {
            return "修改失败";
        }
    }
    
    /**
         * 级联删除俱乐部信息
     * @param request
     * @return
     */
    public String deleteClubinfo(HttpServletRequest request) {
        String clubIds = request.getParameter("clubIds");
        int i =clubInfoService.deleteClubinfo(clubIds);
        if (i > 0) {
            return "删除成功";
        } else  {
            return "删除失败";
        }
    }

}
